<?php

namespace app\api\model;

class Product extends BaseModel
{
    public function productImage()
    {
        return $this->hasMany('ProductImage','product_id','id');
    }

    public function productProperty()
    {
        return $this->hasMany('ProductProperty','product_id','id');
    }

    
    public static function getOne($id)
    {
                    //with 关联载入关键词
        return self::with([
                    //闭包查询
            'productImage' => function($query){
                    //针对查询出来的结果排序,这个不需要return
                $query->order('order','asc')->with(['img']);
            },'productProperty'
        ])->find($id);
    }

    public static function getRecentProduct($count)
    {
        return self::limit($count)->order('create_time desc')->select();
    }
}
